package com.test.daily.leetcode.y2021.m10.day1031;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 * @descriptions: findWord
 * @author: Tom
 * @date: 2021/10/31 下午 10:25
 * @version: 1.0
 */
public class Code01_FindWords {

    public static void main(String[] args) {
        String[] words = new String[]{"Hello","Alaska","Dad","Peace"};
        Code01_FindWords cf = new Code01_FindWords();
        cf.findWords(words);
    }

    public String[] findWords(String[] words) {
        /**
         * 第一行由字符 "qwertyuiop" 组成。
         * 第二行由字符 "asdfghjkl" 组成。
         * 第三行由字符 "zxcvbnm" 组成
         */
        int[] map = new int[26];
        char[] firstLine = new char[]{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'};
        char[] secondLine = new char[]{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'};
        char[] thirdLine = new char[]{'z', 'x', 'c', 'v', 'b', 'n', 'm'};
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < firstLine.length; j++) {
                if (i + 'a' == firstLine[j]) {
                    map[i] = 1;
                }
            }
            for (int k = 0; k < secondLine.length; k++) {
                if ((i + 'a') == secondLine[k]) {
                    map[i] = 2;
                }
            }
            for (int l = 0; l < thirdLine.length; l++) {
                if ((i + 'a') == thirdLine[l]) {
                    map[i] = 3;
                }
            }
        }
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < words.length; i++) {
            String element = words[i].toLowerCase();
            int firstOne = map[element.charAt(0) - 'a'];
            boolean flag = true;
            for (int j = 1; j < element.length(); j++) {
                if (map[element.charAt(j) - 'a'] != firstOne) {
                    flag = false;
                    break;
                }

            }
            if(flag){
                list.add(i);
            }
        }
        String[] ans = new String[list.size()];
        for(int k = 0; k < list.size(); k++){
            ans[k] = words[list.get(k)];
        }
        return ans;
    }
}
